import axios from "axios";

const http = axios.create({
  baseURL: "/api",
  timeout: 2000,
});

http.interceptors.request.use(
  (config) => {
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);

http.interceptors.response.use(
  (res) => {
    if(res.status === 200) {
      return res.data
    } else {
      return Promise.reject(res.message);
    }
  },
  (error) => {
    return Promise.reject(error);
  }
);

export const httpGet = (url, params) => {
  return http.get(url, {
    params,
  });
};

export const httpPost = (url, data) => {
  return http.post(url, {
    data,
  });
};
